<?php
namespace Admin\Controller;

use Think\Controller;

class FinanceController extends CommenController{


    public function test_charging(){
        $data['orderno'] = '201809201562655655555966696';//订单号
        $data['username'] = '杨靖';//收账用户名
        $data['money'] = 0.01;//转账金额
        $data['bank_number'] = '6217000210003441168';//收账银行卡号
        $data['pay_type'] = 'P';//账户类型，对私：传P，对公：传C
        $data['bank_code'] = 'CCB';//银行卡编号（参考以下数据表内容）
        $data['bank_card_type'] = 'DE';//银行卡类型，借记卡=DE，信用卡=CR
        $data['notify_url'] = 'http://xycshopv2.xycpro.com/Pay/notify';//回调地址
        $data['descript'] = '测试';//订单描述
        $data['create_bank'] = '中国建设银行股份有限公司廊坊燕郊学院大街支行';//银行具体名称，比如中国建设银行股份有限公司平阳昆阳支行
        $jd_balance_result = $this->get_balance();
        $jd_balance = $jd_balance_result['code'];
        if($data['money']>$jd_balance){
            $msg["code"] = 1002;
            $msg["result"] = '打款方余额不足';
            var_dump($msg);die;
        }

        $url = "https://pay.dstlkj.com/External/external_jd_payment";        
        $result = $this->curl_post_https($url,$data);
        parse_str($result,$parr);
        $trade_subject = trim($parr['trade_subject'],'\"测试\"');
        $result = json_decode($trade_subject,true);
        // if($result['ret']==1001){
        //     MycommonController::ajax('1001','打款成功');            
        // }else{
        //     MycommonController::ajax('1002', $result['code']);
        // }
        var_dump($result);
    }
    // 查询京东账户余额
    public function get_balance(){
        $url = 'https://pay.dstlkj.com/External/external_get_jd_balance';
        $data['xycjd'] = 'xycjd';
        $result = $this->curl_post_https($url,$data);
        $result = json_decode($result,true);
        return $result;
        // var_dump($result);

    }
    // 京东打款
    public function Charging($orderno,$username,$money,$bank_number,$descript,$create_bank,$bank_code,$bank_card_type,$pay_type='P'){
        $data['orderno'] = $orderno;//订单号
        $data['username'] = $username;//收账用户名
        $data['money'] = $money;//转账金额
        $data['bank_number'] = $bank_number;//收账银行卡号
        $data['pay_type'] = $pay_type;//账户类型，对私：传P，对公：传C
        $data['bank_code'] = $bank_code;//银行卡编号（参考以下数据表内容）
        $data['bank_card_type'] = $bank_card_type;//银行卡类型，借记卡=DE，信用卡=CR
        $data['notify_url'] = 'http://xycshopv2.xycpro.com/Pay/notify';//回调地址
        $data['descript'] = $descript;//订单描述
        $data['create_bank'] = $create_bank;//银行具体名称，比如中国建设银行股份有限公司平阳昆阳支行

        $url = "https://pay.dstlkj.com/External/external_jd_payment";        
        // return $data;
        // $result = $this->curl_post_https($url,$data);
        $result = http($url,$data,1);
        parse_str($result,$parr);
        $trade_subject = trim($parr['trade_subject'],'\"'.$descript.'\"');
        $result = json_decode($trade_subject,true);
//        file_put_contents('./Public/log/jd_active_notify.log', date('Y-m-d H:i:s').'成功回调' .json_encode($data) . "\n", FILE_APPEND);

        if($result['ret']==1001){
            $res['status'] = 1001;
            $res['info'] = '打款成功，等待支付结果，处理中';
            return $res;
        }else{
            $res['status'] = 1002;
            $res['info'] = $result['code'];
            return $res;
        }
    }

    function curl_post_https($url,$data){ // 模拟提交数据函数
        $curl = curl_init(); // 启动一个CURL会话
        curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在
        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
        curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
        curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
        curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容    
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
        $tmpInfo = curl_exec($curl); // 执行操作
        if (curl_errno($curl)) {
            echo 'Errno'.curl_error($curl);//捕抓异常
        }
        curl_close($curl); // 关闭CURL会话
        return $tmpInfo; // 返回数据，json格式

    }

    //银行卡
    public function bind_bank(){
        if(IS_POST){
            $username =I("username");
            $mobile =I("mobile");
            $bank_number =I("bank_number");
            $create_bank =I("create_bank");
            $bank_code = I("bank_code");
            $bank_card_type = I("bank_card_type");
            $merchant_bind_bank = M('merchant_bind_bank','','XYC');
            $data = array('shop_identifier'=>$_SESSION['shop_identifier'],'username'=>$username,'mobile'=>$mobile,'bank_number'=>$bank_number,'bank_code'=>$bank_code,'bank_card_type'=>$bank_card_type,'create_bank'=>$create_bank,'ctime'=>time());
            $res = $merchant_bind_bank->add($data);
            if($res){
                $msg["code"] = 1001;
                $msg["result"] = "添加成功";
                $this->ajaxReturn($msg);
            }else{
                $msg["code"] = 1002;
                $msg["result"] = "添加失败";
                $this->ajaxReturn($msg);
            }
        }
        $bank_code = M('jd_bank_info','','XYC')->select();
        $bank_msg = M('merchant_bind_bank','','XYC')->where(array('shop_identifier'=>$_SESSION['shop_identifier']))->find();
        $this->assign(array(
            'bank_code' => $bank_code,
            'bank_msg' => $bank_msg
        ));
        $this->display();
    }

    //打款处理列表
    public function remittance_list(){
        $shop_identifier = $_SESSION['shop_identifier'];
        $where = array();
        $vz_loan = M('vz_loan','','XYC');
        $user = M("user",'','XYC');
        $merchant = M("merchant",'','XYC');
        $content = trim(I("get.content"));
        $start = I("get.start");
        $end = I("get.end");
        $start = strtotime($start);
        $end = strtotime($end);
        if($start&&$end){
            $where["a.ctime|a.get_time"]=array('between',array($start,$end));
        }elseif ($start){
            $where["a.ctime|a.get_time"]=array('egt',$start);
        }elseif ($end){
            $where["a.ctime|a.get_time"]=array('elt',$end);
        }
        if($content){
            $where["a.order_number|b.username|b.mobile"] = array('like',"$content%");
        }
        if(I('lender')){
            $where['a.lender_id']=I('lender');
        }

        $where['a.shop_identifier']=$shop_identifier;
        $where['a.status'] = 5;
        $where['a.is_success'] = ['neq',3];
        $search_arr=array('start'=>I("get.start"),'end'=>I("get.end"),'content'=>$content,'lender'=>I('lender'));
        $tol = $vz_loan->alias('a')->join('join user b on a.user_id=b.id')->where($where)->count();
        $row = '15';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        $list = $vz_loan->alias('a')->field('a.*,b.username,b.mobile')->join(' join user b on a.user_id=b.id')->where($where)->limit($page->listfirst, $page->listRows)->order("a.ctime DESC")->select();

        //借款人
        $lender=M('lender','','XYC')->where(['id'=>['in',array_column($list,'lender_id')]])->getfield('id,name',true);
        $bank = M('user_bind_bank','','XYC')->field('bankcard_id,bank_name')->where(array('user_id'=>['in',array_column($list,'user_id')],'shop_identifier'=>$_SESSION['shop_identifier']))->getfield('user_id,bankcard_id,bank_name,jd_bank_code,bank_card_type,id as bind_id',true);

//        var_dump($lender);
        foreach($list as $k=>$v){
            $list[$k]['ctime'] = $v['ctime']?date('Y-m-d',$v['ctime']):'';
            $list[$k]['get_time'] = $v['get_time']?date('Y-m-d',$v['get_time']):'';
            $list[$k]['atlast_time'] = $v['atlast_time']?date('Y-m-d',$v['atlast_time']):'';
            $list[$k]['get_time'] = $v['get_time']?date('Y-m-d',$v['get_time']):'';

            $list[$k]['bankcard_id'] =  $bank[$v['user_id']]['bankcard_id'];
            $list[$k]['bank_name'] =  $bank[$v['user_id']]['bank_name'];
            $list[$k]['bank_code'] =  $bank[$v['user_id']]['jd_bank_code'];
            $list[$k]['bind_id'] =  $bank[$v['user_id']]['bind_id'];
            $list[$k]['bank_card_type'] =  $bank[$v['user_id']]['bank_card_type'];
            $list[$k]['lender']=$lender[$v['lender_id']];
            $list[$k]['loan_amount1']=$v['loan_amount']-$v['fee'];
        }

        //出借人
        $this->lender_arr=M('lender','','XYC')->where(['shop_idenfier'=>$_SESSION['shop_identifier'],'is_delete'=>1])->field('id,name')->select();


        //卡code


        // echo '<pre>';var_dump($list);die;
        $this->assign(array(
            'list' => $list,
            'fpage' => $fpage,
            'tol' => $tol,
            'search'=>$search_arr
        ));
        $this->display();
    }

    /**
      获取银行卡
     */
    public function get_bank(){
        $data=M('jd_bank_info','','XYC')->field('bank_name,bank_code')->select();
         $this->ajaxReturn(['code'=>'1001','data'=>$data]);

    }
    /**
     * 绑定银行卡修改
     */

    public function bind_bank_edit()
    {
//        $bank_code=I('bank_code');
//        $bank_name=I('bank_name');
//        $bankcard_id=I('bankcard_id');
//        $bank_type=I('bank_type');
        $bind_id=I('id');

        $data=I('post.');
        $data['utime']=time();
//        $data['shop_identifier']=time();
        if(M('user_bind_bank','','XYC')->where(['id'=>$bind_id])->save($data)){
            $this->ajaxReturn(['code'=>'1001','info'=>'修改成功']);

        }else{
            $this->ajaxReturn(['code'=>'1002','info'=>'修改失败']);

        }



    }


    /**
     * 打款操作
     */
    public function add_remittance(){
        $logo = I('logo');
        $remark = I('remark');
        $numbering = I('numbering');
        if(IS_POST){
            $imgurl = '';
            if (!empty($logo)) {
                $upload = new \Admin\Logic\UploadPicLogic();        //实例化 上传图片
                $picarray = explode('~', $logo);
                $url = "xyc/";
                foreach ($picarray as $k1 => $v1) {
                    $returnimg = $upload->LoadIgoodimg($v1, $url);
                    if ($returnimg['status'] == '1') {
                        // if ($k1 == 0) {
                        //     $imgurl = $returnimg['pic'];
                        // }
                        $imgurl .= $returnimg['pic'].",";
                    } else {
                        $this->ajaxReturn(array('state' => '2', 'result' => '图片上传失败'), 'json');
                        die;
                    }
                }
            }
            // $this->ajaxReturn($imgurl);
            $imgurl = trim($imgurl,",");
            // $this->ajaxReturn($imgurl);
            $arr = array('remark'=>$remark,'remittance_pic'=>$imgurl,'is_success'=>2,'get_time'=>time(),'status'=>1);
            $res = M('vz_loan','','XYC')->where(array('order_number'=>$numbering))->save($arr);
            if($res){

                add_control_log($_SESSION['shop_identifier'],$_SESSION['name'],"添加了打款记录",'3');
                $msg["code"] = 1001;
                $msg["result"] = "操作成功";
                $this->ajaxReturn($msg);
            }else{
                $msg["code"] = 1002;
                $msg["result"] = "操作失败";
                $this->ajaxReturn($msg);
            }
        }
        $this->display('remittance');
    }

    /**
     * 添加打款失败原因
     */
    public function add_reason(){
        if(IS_POST){
            $reason = I('reason');
            $id = I('id');
            $res = M('vz_loan','',"XYC")->where(array('id'=>$id))->save(array('is_success'=>3,'reason'=>$reason));
             //打款失败恢复额度
             $user=M('vz_loan','',"XYC")->where(array('id'=>$id))->field('user_id,loan_amount')->find();

             $update=M('user','','XYC')->where(['id'=>$user['user_id']])->setInc('balance',$user['loan_amount']);

            if($res && $update){
                add_control_log($_SESSION['shop_identifier'],$_SESSION['name'],"添加了打款失败原因",'3');
                $msg["code"] = 1001;
                $msg["result"] = "原因添加成功";
                $this->ajaxReturn($msg);
            }else{
                $msg["code"] = 1002;
                $msg["result"] = "原因添加失败";
                $this->ajaxReturn($msg);
            }
        }
        $this->display();
    }  

     /**
     * 代扣打款
     */
    public function remittance(){
        if(IS_POST){
            $numbering = I('numbering');
            $id = I('id');
            // $this->ajaxReturn('ABC');
            if(empty($numbering)){
                $msg["code"] = 1002;
                $msg["result"] = "订单异常";
                $this->ajaxReturn($msg);
            }else{
                $order = M('vz_loan','','XYC')->field('user_id,loan_amount,fee')->where(array('order_number'=>$numbering))->find();
                $user_id = $order['user_id'];
                if($user_id){
                    $user_bank = M('user_bind_bank','','XYC')->where(array('user_id'=>$user_id))->find();
                    if($user_bank){
                        $username = M('user','','XYC')->where(array('id'=>$user_id))->getField('username');
                        $orderno = $numbering;
                        $money = $order['loan_amount']-$order['fee'];

                        $shop_identifier = $_SESSION['shop_identifier'];
                        $withhold_balance = M('merchant','','XYC')->where(array('shop_identifier'=>$shop_identifier))->getfield('withhold_balance');

//                        var_dump(['money'=>$money,'ba'=>$withhold_balance])
                        if($money>$withhold_balance){
                            $msg["code"] = 1002;
                            $msg["result"] = '代扣余额不足';
                            $this->ajaxReturn($msg);die;
                        }
                        $jd_balance_result = $this->get_balance();
                        $jd_balance = $jd_balance_result['code']/100;

                        if($money>$jd_balance){
                            $msg["code"] = 1002;
                            $msg["result"] = '打款方余额不足';
                            $this->ajaxReturn($msg);die;
                        }
                        $bank_number = $user_bank['bankcard_id'];
                        $create_bank = $user_bank['bank_name'];
                        $bank_code = $user_bank['jd_bank_code'];
                        if(empty($bank_code)){
                            $msg["code"] = 1002;
                            $msg["result"] = "用户银行卡信息异常";
                            $this->ajaxReturn($msg);
                        }
                        $bank_card_type = $user_bank['bank_card_type']==1?'DE':'CR';
                        $descript = '用户借款代扣打款';
                        $data = array('orderno'=>$orderno,'username'=>$username,'money'=>$money,'bank_number'=>$bank_number,'descript'=>$descript,'create_bank'=>$create_bank,'bank_code'=>$bank_code,'bank_card_type'=>$bank_card_type);
                        $result = $this->Charging($orderno,$username,$money,$bank_number,$descript,$create_bank,$bank_code,$bank_card_type);
                        $this->ajaxReturn($result);
                        if($result['status']==1001){
                            $msg["code"] = 1001;
                            $msg["result"] = $result['info'];
                            $this->ajaxReturn($msg);
                        }else{
                            if($result['info']=='参数错误，请联系管理员'){
                                $msg["code"] = 1002;
                                $msg["result"] = "用户信息或银行卡信息异常";
                                $this->ajaxReturn($msg);
                            }else{
                                $this->ajaxReturn($result);
                                $msg["code"] = 1002;
                                $msg["result"] = $result['info'].'，用户信息或银行卡信息异常';
                                $this->ajaxReturn($msg);
                            }
                        }
                    }else{
                        $msg["code"] = 1002;
                        $msg["result"] = "用户未绑定银行卡";
                        $this->ajaxReturn($msg);
                    }
                }else{
                    $msg["code"] = 1002;
                    $msg["result"] = "订单异常";
                    $this->ajaxReturn($msg);
                }
            }            
        }
    }

    /**
     * 还款处理
     */
    public function repayment_list(){
        // $shop_identifier = '0100010020';
        $shop_identifier = $_SESSION['shop_identifier'];
        $where = array();
        $vz_loan = M('vz_loan','','XYC');
        $user = M("user",'','XYC');
        $merchant = M("merchant",'','XYC');
        $content = trim(I("get.content"));
        $start = I("get.start");
        $end = I("get.end");
        $start = strtotime($start);
        $end = strtotime($end);
        if($start&&$end){
            $where["a.atlast_time|a.actual_time"]=array('between',array($start,$end));
        }elseif ($start){
            $where["a.atlast_time|a.actual_time"]=array('egt',$start);
        }elseif ($end){
            $where["a.atlast_time|a.actual_time"]=array('elt',$end);
        }
        if($content){
            $where["a.order_number|b.username|b.mobile"] = array('like',"%$content%");
        }
        if(I('lender')){
            $where['a.lender_id']=I('lender');
        }
        $where['a.shop_identifier']=$shop_identifier;
        $where['a.status']=array('in',array(1,3));
        $search_arr=array('start'=>I("get.start"),'end'=>I("get.end"),'content'=>$content);
        $tol = $vz_loan->alias('a')->join('user b on a.user_id=b.id')->where($where)->count();
        $row = '15';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        $list = $vz_loan->alias('a')->field('a.*,b.username,b.mobile')->join('left join user b on a.user_id=b.id')->where($where)->limit($page->listfirst, $page->listRows)->order("a.actual_time ASC")->select();
        //借款人
        $lender=M('lender','','XYC')->where(['id'=>['in',array_column($list,'lender_id')]])->getfield('id,name',true);

        foreach($list as $k=>$v){
            $status = $v['status'];
            if($status==3){
                $time = time()>$v['atlast_time']?time()-$v['atlast_time']:"";
                $list[$k]['overdue_day'] = ceil($time/(24*3600));
            }
            $list[$k]['totalmoney'] = $v['loan_amount']+$v['overdue_money']-$v['repayment_amount'];
            if( $list[$k]['totalmoney']<0){
                $list[$k]['totalmoney']=0;
            }
            $list[$k]['money'] = M('vz_loan_collection','','XYC')->where(array('order_number'=>$v['order_number']))->sum('money');
            $list[$k]['receiving_teller'] = M('vz_loan_collection','','XYC')->where(array('order_number'=>$v['order_number']))->getField('receiving_teller');
            $list[$k]['ctime'] = $v['ctime']?date('Y-m-d',$v['ctime']):'';
            $list[$k]['get_time'] = $v['get_time']?date('Y-m-d',$v['get_time']):'';
            $list[$k]['atlast_time'] = $v['atlast_time']?date('Y-m-d',$v['atlast_time']):'';
            $list[$k]['actual_time'] = $v['actual_time']?date('Y-m-d',$v['actual_time']):'';
//            $list[$k]['repayment_money'] = M('vz_repayment','','XYC')->where(array('order_number'=>$v['order_number']))->sum('repay_amount');
            $list[$k]['lender']=$lender[$v['lender_id']];
        }

        $this->lender_arr=M('lender','','XYC')->where(['shop_idenfier'=>$_SESSION['shop_identifier'],'is_delete'=>1])->field('id,name')->select();
        $this->assign(array(
            'list' => $list,
            'fpage' => $fpage,
            'tol' => $tol,
            'search'=>$search_arr
        ));
        $this->display();
        //出借人
    }

    /**
     * 添加收款
     */
    public function add_collection(){
        $logo = I('logo');
        $money = I('money');
        $order_number = I('order_number');
        $method = I('method');
        $type = I('type');
        $overdue_money = I('overdue_money');
        $time = I('start')?strtotime(I('start')):'';
        if(IS_POST){
            $imgurl = '';
            if (!empty($logo)) {
                $upload = new \Admin\Logic\UploadPicLogic();        //实例化 上传图片
                $picarray = explode('~', $logo);
                $url = "xyc/";
                foreach ($picarray as $k1 => $v1) {
                    $returnimg = $upload->LoadIgoodimg($v1, $url);
                    if ($returnimg['status'] == '1') {
                        // if ($k1 == 0) {
                        //     $imgurl = $returnimg['pic'];
                        // }
                        $imgurl .= $returnimg['pic'].",";
                    } else {
                        $this->ajaxReturn(array('state' => '2', 'result' => '图片上传失败'), 'json');
                        die;
                    }
                }
            }
            // $this->ajaxReturn($imgurl);
            $imgurl = trim($imgurl,",");
            $arr = array('warrant'=>$imgurl,'money'=>$money,'order_number'=>$order_number,'method'=>$method,'type'=>$type,'overdue_money'=>$overdue_money,'receiving_teller'=>$_SESSION['name'],'ctime'=>time(),'period_time'=>$time,'shop_identifier'=>$_SESSION['shop_identifier']);
            if($type==1){
                M('vz_loan','','XYC')->where(array('order_number'=>$order_number))->save(array('status'=>2,'actual_time'=>time()));
            }else{
                M('vz_loan','','XYC')->where(array('order_number'=>$order_number))->save(array('actual_time'=>time()));
            }            
            M('vz_loan','','XYC')->where(array('order_number'=>$order_number))->setInc('repayment_amount',$money);
            $res = M('vz_loan_collection','','XYC')->add($arr);            
            if($res){
                add_control_log($_SESSION['shop_identifier'],$_SESSION['name'],"添加了收款",'3');
                $msg["code"] = 1001;
                $msg["result"] = "添加成功";
                $this->ajaxReturn($msg);
            }else{
                $msg["code"] = 1002;
                $msg["result"] = "添加失败";
                $this->ajaxReturn($msg);
            }
        }
        $this->display();

    }

    /**
     * 收款明细
     */
    public function collection_schedule(){
        $order_number = I("order_number");
        if($order_number){
            $vz_loan_collection = M("vz_loan_collection",'','XYC');
            $where["order_number"] = $order_number;
            $list = $vz_loan_collection->where($where)->order("ctime DESC")->limit(20)->select();
            foreach($list as $k=>$v){
                $list[$k]["ctime"] = date("Y-m-d",$v['ctime']);
                $img = $v['warrant'];
                $imgArr = explode(',',$img);
                $imgStr = '';
                foreach($imgArr as $vv){
                    $imgStr .= '<div class="example col-xs-1 col-md-1"><span class="picture"><img width="100px" height="100px" src="'.$vv.'" class="zoomify" style="transform: scale(1) translate(0px, 0px);"></span></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                }
                $list[$k]['warrant'] = $imgStr;
                // 收款方式（自动、支付宝、微信、银行卡）、还款类型（全额还款、部分还款、续期、还利息）
                if($v['method']==1){
                    $list[$k]["method"] = '自动';
                }elseif($v['method']==2){
                    $list[$k]["method"] = '支付宝';
                }elseif($v['method']==3){
                    $list[$k]["method"] = '微信';
                }elseif($v['method']==4){
                    $list[$k]["method"] = '银行卡';
                }
                if($v['type']==1){
                    $list[$k]["type"] = '全额还款';
                }elseif($v['type']==2){
                    $list[$k]["type"] = '部分还款';
                }elseif($v['type']==3){
                    $list[$k]["type"] = '续期';
                }elseif($v['type']==4){
                    $list[$k]["type"] = '还利息';
                }
            }
        }
        $this->assign(array(
            'list' => $list
        ));
        $this->display();
    }

    public function get_more_record(){
        $order_number = I("order_number");
        $m_c_num = I("m_c_num");
        if($order_number){
            $num = 20*$m_c_num-20;
            $vz_loan_collection = M("vz_loan_collection",'','XYC');
            $where["order_number"] = $order_number;
            $list = $vz_loan_collection->where($where)->order("ctime DESC")->limit("$num,20")->select();
            foreach($list as $k=>$v){
                $list[$k]["ctime"] = date("Y-m-d",$v['ctime']);
                $img = $v['warrant'];
                $imgArr = explode(',',$img);
                $imgStr = '';
                foreach($imgArr as $vv){
                    $imgStr .= '<div class="example col-xs-1 col-md-1"><span class="picture"><img width="100px" height="100px" src="'.$vv.'" class="zoomify" style="transform: scale(1) translate(0px, 0px);"></span></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                }
                $list[$k]['warrant'] = $imgStr;
                $list[$k]["ctime"] = date("Y-m-d",$v['ctime']);
                if($v['method']==1){
                    $list[$k]["method"] = '自动';
                }elseif($v['method']==2){
                    $list[$k]["method"] = '支付宝';
                }elseif($v['method']==3){
                    $list[$k]["method"] = '微信';
                }elseif($v['method']==4){
                    $list[$k]["method"] = '银行卡';
                }
                if($v['type']==1){
                    $list[$k]["type"] = '全额还款';
                }elseif($v['type']==2){
                    $list[$k]["type"] = '部分还款';
                }elseif($v['type']==3){
                    $list[$k]["type"] = '续期';
                }elseif($v['type']==4){
                    $list[$k]["type"] = '还利息';
                }
            }
            $msg["code"] = 1001;
            $msg["result"] = $list;
            $this->ajaxReturn($msg);
        }else{
            $msg["code"] = 1002;
            $msg["result"] = "账户异常！";
            $this->ajaxReturn($msg);
        }
    }

    /**
     * 费用减免
     */
    public function cost_reduction(){
        // $shop_identifier = '0100010020';
        $shop_identifier = $_SESSION['shop_identifier'];
        $where = array();
        $user_overdue = M('user_overdue','','XYC_SERVICE');
        $user = M("user",'','XYC');
        $merchant = M("merchant",'','XYC');
        $content = trim(I("get.content"));
        $start = I("get.start");
        $end = I("get.end");
        $start = strtotime($start);
        $end = strtotime($end);
        if($start&&$end){
            $where["ctime|overdue_time"]=array('between',array($start,$end));
        }elseif ($start){
            $where["ctime|overdue_time"]=array('egt',$start);
        }elseif ($end){
            $where["ctime|overdue_time"]=array('elt',$end);
        }
        if($content){
            $where["username|mobile"] = array('like',"%$content%");
        }
        $where['shop_identifier']=$shop_identifier;
        $where['status']=1;        
        // $where['version'] = 'v2';
        $search_arr=array('start'=>I("get.start"),'end'=>I("get.end"),'content'=>$content);
        $tol = $user_overdue->where($where)->count();
        $row = '15';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        $list = $user_overdue->where($where)->limit($page->listfirst, $page->listRows)->order("ctime DESC")->select();
        //借款人
        $lender=M('vz_loan','','XYC')->join('a join lender b on b.id=a.lender_id')->where(['a.order_number'=>['in',array_column($list,'numbering')]])->getfield('a.order_number,b.name');
        foreach($list as $k=>$v){
            $user_id = $v['user_id'];
            $userData = $user->where(array('id'=>$user_id))->field('username,mobile')->find();
            $list[$k]['username'] = $userData['username'];
            $list[$k]['admname'] = M('shopkeeper','',"XYC")->where(array('id'=>$v['ua_id']))->getField('name');
            $list[$k]['mobile'] = $userData['mobile'];
            $list[$k]['overdue_time'] = $v['overdue_time']?date('Y-m-d',$v['overdue_time']):'';
            $list[$k]['should_time'] = $v['should_time']?date('Y-m-d',$v['should_time']):'';
            $remark = M('overdue_remark','',"XYC")->where(array('numbering'=>$v['numbering']))->order('ctime DESC')->select();
            $list[$k]['final_time'] = $remark[0]['ctime']?date('Y-m-d',$remark[0]['ctime']):'';
            $list[$k]['remarkcount'] = count($remark);
            $list[$k]['lender']=$lender[$v['order_number']];
            
        }
        // echo '<pre>';var_dump($list);die;
        $this->assign(array(
            'list' => $list,
            'fpage' => $fpage,
            'tol' => $tol,
            'search'=>$search_arr
        ));
        $this->display();
    }

    /**
     * 费用减免
     */
    public function add_reduce(){
        if(IS_POST){
            $reduce_money = I('reduce_money');
            $reduce_remark = I('reduce_remark');
            $id = I('id');
            $res =  M('user_overdue','','XYC_SERVICE')->where(array('id'=>$id))->save(array('reduce_remark'=>$reduce_remark,'reduce_money'=>$reduce_money));
            if($res){
                add_control_log($_SESSION['shop_identifier'],$_SESSION['name'],"添加了费用减免",'3');
                $msg["code"] = 1001;
                $msg["result"] = "费用减免成功";
                $this->ajaxReturn($msg);
            }else{
                $msg["code"] = 1002;
                $msg["result"] = "费用减免失败";
                $this->ajaxReturn($msg);
            }
        }
        $this->display();
    }


    //订单管理
    public function order_list(){
        // $shop_identifier = '0100010020';
        $shop_identifier = $_SESSION['shop_identifier'];
        $where = array();
        $vz_loan = M('vz_loan','','XYC');
        $user = M("user",'','XYC');
        $merchant = M("merchant",'','XYC');
        $content = trim(I("get.content"));
        $start = I("get.start");
        $end = I("get.end");
        $start = strtotime($start);
        $end = strtotime($end);
        $status = I('status');
        if($start&&$end){
            $where["a.ctime|a.atlast_time|a.actual_time"]=array('between',array($start,$end));
        }elseif ($start){
            $where["a.ctime|a.atlast_time|a.actual_time"]=array('egt',$start);
        }elseif ($end){
            $where["a.ctime|a.atlast_time|a.actual_time"]=array('elt',$end);
        }
        if($content){
            $where["a.order_number|b.username|b.mobile"] = array('like',"%$content%");
        }
        if(!empty($status)){
            if($status=='z'){
                $where['a.status']=0;
            }else{
                $where['a.status']=$status;
            }            
        }
        if(I('lender')){
            $where['a.lender_id']=I('lender');
        }
        $where['a.shop_identifier']=$shop_identifier;
        // $where['status']=1;
        $search_arr=array('start'=>I("get.start"),'end'=>I("get.end"),'content'=>$content,'status'=>$status);
        $tol = $vz_loan->alias('a')->join('user b on a.user_id=b.id')->where($where)->count();
        $row = '15';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        $list = $vz_loan->alias('a')->field('a.*,b.username,b.mobile')->join('left join user b on a.user_id=b.id')->where($where)->limit($page->listfirst, $page->listRows)->order("a.ctime DESC")->select();
        //借款人
        $lender=M('lender','','XYC')->where(['id'=>['in',array_column($list,'lender_id')]])->getfield('id,name',true);
        foreach($list as $k=>$v){
            
            $list[$k]['ctime'] = $v['ctime']?date('Y-m-d',$v['ctime']):'';
            $list[$k]['get_time'] = $v['get_time']?date('Y-m-d',$v['get_time']):'';
            $list[$k]['atlast_time'] = $v['atlast_time']?date('Y-m-d',$v['atlast_time']):'';
            $list[$k]['actual_time'] = $v['actual_time']?date('Y-m-d',$v['actual_time']):'';
            $list[$k]['repayment_money'] = M('vz_repayment','','XYC')->where(array('order_number'=>$v['order_number']))->sum('repay_amount');
            $list[$k]['lender']=$lender[$v['lender_id']];

            switch ($v['status']){
                case 0: $list[$k]['status']='待审核';   break;
                case 1: $list[$k]['status']='未还款';   break;
                case 2: $list[$k]['status']='已还款';   break;
                case 3: $list[$k]['status']='已逾期';   break;
                case 4: $list[$k]['status']='被拒绝';   break;
                case 5: $list[$k]['status']='待打款';   break;
                case 6: $list[$k]['status']='坏账';   break;


            }


        }
        $this->lender_arr=M('lender','','XYC')->where(['shop_idenfier'=>$_SESSION['shop_identifier'],'is_delete'=>1])->field('id,name')->select();
        $this->assign(array(
            'list' => $list,
            'fpage' => $fpage,
            'tol' => $tol,
            'search'=>$search_arr
        ));
        $this->display();
    }


    /**
     * 财务信息
     */
    public function finance_statistics(){
        $certificate_db = D('Certificate');
        $channel_db=M('channel','','XYC');
        $time = !empty(I('time')) ? I('time') : 'ctime';
        $where = MycommonController::set_where(array('status'), array('numbering','borrower', 'card_id', 'lender', 'mobile'), $time);
        if(!empty(I('content'))){
            $channel=$channel_db->WHERE(['channel_name'=>I('content')])->getField('chan_id');
            if(!empty($channel)){
                $where['_string']="channel='$channel'";
            }
        }
        $where['shop_identifier'] = $_SESSION['shop_identifier'];
        $where['is_delete'] = '1';
        $tol = $certificate_db->WHERE($where)->COUNT();
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        $list = $certificate_db->WHERE($where)->FIELD("id")->LIMIT($page->listfirst, $page->listRows)->ORDER("id desc")->SELECT();
        $list = array_column($list, 'id');
        $list = $certificate_db->WHERE(['id' => ['in', $list]])->ORDER("id desc")->SELECT();

        foreach ($list as $k => $v) {
            $list[$k]['ctime'] = date('Y-m-d', $v['ctime']);
            $list[$k]['repayment_time'] = date('Y-m-d', $v['repayment_time']);
            $list[$k]['loan_time'] = date('Y-m-d', $v['loan_time']);
            $list[$k]['tear_time'] = !empty($v['tear_time']) ? date('Y-m-d', $v['tear_time']) : '';
            $list[$k]['channel']=$channel_db->WHERE(['chan_id'=>$v['channel']])->getField('channel_name');

        }
        $this->assign(array(
            'list' => $list,
            'fpage' => $fpage,
            'tol' => $tol,
            'rate' => json_encode(range(1, 24))
        ));
        $this->display();
    }

    /**
     * 七天数据统计
     */
    public function data_statistics(){
        $user_db = M('user', '', 'XYC');//用户表
        $user_examine_db = M('user_examine', '', 'XYC');//用户表
        $certificate_db=M('certificate','','XYC');//凭证表
        $shop_all_data_statistics_db=M('shop_all_data_statistics','','XYC');
        $choose_time=!empty(I('get.time'))?strtotime(I('get.time')):time();
        $a=['2','3','4','5','6','9'];//除未确定和拒绝的都算借款成功
        $time=[strtotime(date('Y-m-d', $choose_time)), strtotime(date('Y-m-d 23:59:59', $choose_time))];
        $shop_identifier=$_SESSION['shop_identifier'];
        $statistics_msg=$shop_all_data_statistics_db->WHERE(['shop_identifier'=>$shop_identifier])->FIND();

        $where['shop_identifier']=$shop_identifier;
        $data['all_user']=$statistics_msg['all_user'];//总用户数
        $data['all_borrow_user']=$statistics_msg['all_borrow_user'];//总借款人数
        $data['all_overdue_user']=$statistics_msg['all_overdue_user'];//总逾期人数

        $where_today['loan_time']=['between',$time];
        $where_today['status']=['in',$a];
        $where_today['shop_identifier']=$shop_identifier;
        $data['today_borrow']=$certificate_db->WHERE($where_today)->COUNT();//今日订单数

        $data['today_borrow_money']=$certificate_db->WHERE($where_today)->SUM('money');
        $data['today_borrow_money']=empty($data['today_borrow_money'])?0:$data['today_borrow_money'];//今日借款额

        $where_today2['ctime']=['between',$time];
        $where_today2['shop_identifier']=$shop_identifier;
        $data['today_user']=$user_db->WHERE($where_today2)->COUNT();//今日进件数

        $where_today3['shop_identifier']=$_SESSION['shop_identifier'];
        $where_today3['cert_status']='2';
        $where_today3['cert_time']='2';
        $data['today_pass']=$user_db->WHERE($where_today3)->COUNT();//今日通过数

        //总认证人数
        $over_cert_user_count=$user_examine_db->JOIN("a JOIN user b ON a.user_id=b.id")->WHERE(['b.ctime'=>['between',$time],'b.shop_idenfire'=>$shop_identifier])->GROUP('a.user_id')->FIELD('a.user_id')->SELECT();
        $user_cert_pass=$user_db->WHERE(['ctime'=>['between',$time],'id'=>['in',array_column($over_cert_user_count,'user_id')],'cert_status'=>'2'])->COUNT();
        $data['today_pass_p']=round($user_cert_pass/count($over_cert_user_count),'3')*100;//今日通过率
        $data['today_pass_p']=empty($data['today_pass_p'])?0:$data['today_pass_p'].'%';


        //近7天的数据
        $redis=MycommonController::mk_redis();
        $date=array();  //日期
        $add_user = array();  //每小时新增人数
        $cert_user = array();  //每小时认证人数
        $borrow_money = array(); //每小时借款金额
        $repayment_money = array();  //每小时还款金额

        //当天以及前7天每天的新增人数和通过率
        $time_s=date('Ymd',$choose_time);
        if(empty($redis->get($time_s.$shop_identifier.RedisPrefixController::ADD_USER))){
            for ($i = 7; $i >= 0; $i--) {
                //0表示当天
                if ($i == 0) {
                    $date[] = date('Y-m-d',$choose_time);
                    $time = array(strtotime(date('Y-m-d', $choose_time)), strtotime(date('Y-m-d 23:59:59', $choose_time)));
                    $add_user_where['ctime']=array('between',$time);
                    $add_user_where['shop_identifier']=$shop_identifier;
                    $add_user[]=$user_db->WHERE($add_user_where)->COUNT();
                    $over_cert_user_count=$user_examine_db->JOIN("a JOIN user b ON a.user_id=b.id")->WHERE(['b.ctime'=>['between',$time],'b.shop_identifier'=>$shop_identifier])->GROUP('a.user_id')->FIELD('a.user_id')->SELECT();
                    $cert_users=$user_db->WHERE(['ctime'=>['between',$time],'id'=>['in',array_column($over_cert_user_count,'user_id')],'cert_status'=>'2'])->COUNT();
                    $cert_user[]=!empty($cert_users)?$cert_users:0;

                }else{
                    $date[] = date('Y-m-d',strtotime("-{$i} day",$choose_time));
                    $time = array(strtotime(date('Y-m-d', strtotime("-{$i} day",$choose_time))), strtotime(date('Y-m-d 23:59:59', strtotime("-{$i} day",$choose_time)))); //前一天
                    $add_user_where['ctime']=array('between',$time);
                    $add_user_where['shop_identifier']=$shop_identifier;
                    $add_user[]=$user_db->WHERE($add_user_where)->COUNT();

                    $over_cert_user_count=$user_examine_db->JOIN("a JOIN user b ON a.user_id=b.id")->WHERE(['b.ctime'=>['between',$time],'b.shop_identifier'=>$shop_identifier])->GROUP('a.user_id')->FIELD('a.user_id')->SELECT();
                    $cert_users=$user_db->WHERE(['ctime'=>['between',$time],'id'=>['in',array_column($over_cert_user_count,'user_id')],'cert_status'=>'2'])->COUNT();
                    $cert_user[]=!empty($cert_users)?$cert_users:0;
                }
            }

            //当天以及前7天每天的借款金额
            for ($i = 7; $i >= 0; $i--) {
                //0表示当天
                if ($i == 0) {
                    $time = array(strtotime(date('Y-m-d', $choose_time)), strtotime(date('Y-m-d 23:59:59', $choose_time)));
                    $borrow_where['ctime']=array('between',$time);
                    $borrow_where['status']=array('in',$a);
                    $borrow_where['shop_identifier']=$shop_identifier;
                    $borrow_m=$certificate_db->WHERE($borrow_where)->SUM('money');
                    $borrow_money[]=!empty($borrow_m)?$borrow_m:'0';
                }else{
                    $time = array(strtotime(date('Y-m-d', strtotime("-{$i} day",$choose_time))), strtotime(date('Y-m-d 23:59:59', strtotime("-{$i} day",$choose_time)))); //前一天
                    $borrow_where['ctime']=array('between',$time);
                    $borrow_where['status']=array('in',$a);
                    $borrow_where['shop_identifier']=$shop_identifier;
                    $borrow_m=$certificate_db->WHERE($borrow_where)->SUM('money');
                    $borrow_money[]=!empty($borrow_m)?$borrow_m:'0';
                }
            }

            //当天以及前7天每天的还款金额
            for ($i = 7; $i >= 0; $i--) {
                //0表示当天
                if ($i == 0) {
                    $time = array(strtotime(date('Y-m-d', $choose_time)), strtotime(date('Y-m-d 23:59:59', $choose_time)));
                    $repayment_where['tear_time']=array('between',$time);
                    $repayment_where['status']='6';
                    $repayment_where['shop_identifier']=$shop_identifier;
                    $repayment_m=$certificate_db->WHERE($repayment_where)->SUM('actual_money');
                    $repayment_money[]=!empty($repayment_m)?$repayment_m:0;
                }else{
                    $time = array(strtotime(date('Y-m-d', strtotime("-{$i} day",$choose_time))), strtotime(date('Y-m-d 23:59:59', strtotime("-{$i} day",$choose_time)))); //前一天
                    $repayment_where['tear_time']=array('between',$time);
                    $repayment_where['status']='6';
                    $repayment_where['shop_identifier']=$shop_identifier;
                    $repayment_m=$certificate_db->WHERE($repayment_where)->SUM('actual_money');
                    $repayment_money[]=!empty($repayment_m)?$repayment_m:0;
                }
            }
            $redis->setex($time_s.$shop_identifier.RedisPrefixController::ADD_USER,3600,json_encode($add_user));
            $redis->setex($time_s.$shop_identifier.RedisPrefixController::CERT_USER,3600,json_encode($cert_user));
            $redis->setex($time_s.$shop_identifier.RedisPrefixController::BORROW_MONEY,3600,json_encode($borrow_money));
            $redis->setex($time_s.$shop_identifier.RedisPrefixController::REPAYMENT_MONEY,3600,json_encode($repayment_money));
            $redis->setex($time_s.$shop_identifier.RedisPrefixController::DATE,3600,json_encode($date));
        }else{
            $add_user=json_decode($redis->get($time_s.$shop_identifier.RedisPrefixController::ADD_USER));
            $cert_user=json_decode($redis->get($time_s.$shop_identifier.RedisPrefixController::CERT_USER));
            $borrow_money=json_decode($redis->get($time_s.$shop_identifier.RedisPrefixController::BORROW_MONEY));
            $repayment_money=json_decode($redis->get($time_s.$shop_identifier.RedisPrefixController::REPAYMENT_MONEY));
            $date=json_decode($redis->get($time_s.$shop_identifier.RedisPrefixController::DATE));
        }

        $this->assign(array(
            'date'=>json_encode($date),
            'add_user'=>json_encode($add_user),
            'cert_user'=>json_encode($cert_user),
            'borrow_money'=>json_encode($borrow_money),
            'repayment_money'=>json_encode($repayment_money),
            'data'=>$data
        ));
        $this->display();
    }


    /**
     * 充值
     */
    public function recharge(){
        $this->display();
    }

    /**
     * 充值方法
     */
    public function recharge_func(){
        if(IS_POST) {
            $time=time();
            $data=I('post.');
            if($data['type']==1){
                $temp=100;
                $type='MCZ';
            }elseif ($data['type']==2){
                $temp=500;
                $type='ACZ';
            }elseif ($data['type']==5){
                // $temp=500;
                $temp=1;
                $type='WCZ';
                $consume_type = M('merchant','','XYC')->where(array('shop_identifier'=>$_SESSION['shop_identifier']))->field("consume_type");
                if($consume_type==1){
                    $data['discount_money'] = $data['money']*0.996;
                }elseif($consume_type==3){
                    $data['discount_money'] = $data['money']*0.992;
                }
            }else{
                MycommonController::ajax('1002', '非法请求操作');
            }
            if ($data['money']<$temp){
                MycommonController::ajax('1002','充值金额必须大于等于'.$temp);
            }
            $data['shop_identifier']=$_SESSION['shop_identifier'];
            $data['order_num']=$type.date('Ymd',$time).rand(100000,999999);
            $data['status']=3;
            $data['ctime']=$time;
            $data['operator']=$_SESSION['name'];
            $data['account']=$_SESSION['account'];
            $data['mobile']=$_SESSION['mobile'];
            if(M('shop_transactions_record','','XYC')->add($data)){
                MycommonController::ajax('1001',$data['order_num']);
            }else{
                MycommonController::ajax('1002', '生成充值订单失败！');
            }

        }else{
            MycommonController::ajax('1002', '非法请求操作');
        }
    }

    /**
     * 调到支付宝充值
     */
    public function alipay_recharge(){
        $data=M('shop_transactions_record','','XYC')->where(['order_num'=>I('order_num')])->field('shop_identifier,order_num,money,type')->find();
        if($data['type']==1){
            $data['order_name']='短信充值';
        }else if($data['type']==2){
            $data['order_name']='认证充值';
        }else if($data['type']==5){
            $data['order_name']='代扣充值';
        }
        $data['content']=$data['order_name'].$data['money'].'元';
        $this->data=$data;
        $this->display();
    }

    function http($url, $content, $ispost = 1, $header = [], $verify = false)
    {
        $httpInfo = array();
        $ch = curl_init();
        if (!empty($header)) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        }
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        //忽略ssl证书
        if ($verify === true) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        } else {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        }
        if ($ispost) {
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
            curl_setopt($ch, CURLOPT_URL, $url);
        } else {
            if (is_array($content)) {
                $params = http_build_query($content);
            }
            if ($params) {
                curl_setopt($ch, CURLOPT_URL, $url . '?' . $params);
            } else {
                curl_setopt($ch, CURLOPT_URL, $url);
            }
        }

        $response = curl_exec($ch);
        if ($response === FALSE) {
            trace("cURL Error: " . curl_errno($ch) . ',' . curl_error($ch), 'error');
            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            $httpInfo = array_merge($httpInfo, curl_getinfo($ch));
            trace($httpInfo, 'error');
            return false;
        }
        curl_close($ch);
        return $response;
    }

    /**
     * 京东二维码
     */
    public function jd_qr(){
        $data=M('shop_transactions_record','','XYC')->where(['order_num'=>I('order_num')])->field('shop_identifier,order_num,money,type')->find();
        if($data['type']==5){
            $url='https://pay.dstlkj.com/External/external_jd_pay';
            $to_url='http://xycshopv2.xycpro.com/Pay/echo_pay';
            $notify_url='http://xycshopv2.xycpro.com/Pay/jd_notify';
            $param=['orderno'=>$data['order_num'],
                'money'=>$data['money'],
                'call_back_url'=>$to_url,
                'notify_url'=>$notify_url];
            $result=$this->http($url,$param,1);
            $result=json_decode($result,true);
//            $this->ajaxReturn(['code'=>$result]);
            Vendor('phpqrcode.phpqrcode');
            $text = $result['code'];
            \QRcode::png($text,false,'M',5,1,false);
            die;
        }
    }

    /**
     * 电脑端唤醒 支付宝扫码支付接口
     */
    public function aliPayPage(){
        $data=M('shop_transactions_record','','XYC')->where(['order_num'=>I('order_num')])->field('shop_identifier,order_num,money,type')->find();

        if($data['type']==1){
            $proName ='短信充值';
        }else{
            $proName ='认证充值';
        }
        $order_amount=$data['money'];
        $content=$proName.$data['money'].'元';
        $out_trade_no = I('order_num');
        Vendor('Alipay.aop.AopClient');
        Vendor('Alipay.aop.request.AlipayTradePagePayRequest');
        //构造参数
        $aop = new \AopClient();
        $aliConfig = C('ALI_CONFIG');
        $aop->gatewayUrl = $aliConfig['gatewayUrl'];
        $aop->appId = $aliConfig['appId'];
        $aop->rsaPrivateKey = $aliConfig['rsaPrivateKey'];
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset= 'utf-8';
        $aop->format='json';
        $request = new \AlipayTradePagePayRequest ();
        $request->setReturnUrl($aliConfig['returnPcUrl']);
        $request->setNotifyUrl($aliConfig['notifyUrl']);
        $request->setBizContent('{"product_code":"FAST_INSTANT_TRADE_PAY","out_trade_no":"'.$out_trade_no.'","subject":"'.$proName.'","total_amount":"'.$order_amount.'","body":"'.$content.'"}');
        //请求
        $result = $aop->pageExecute ($request);

        //输出
        MycommonController::ajax('1001', $result);
    }

}